# -*- codeing = utf-8 -8
import numpy as np
import pandas as pd
from pyecharts.charts import Pie,Map,Tree,WordCloud,Liquid,Bar,EffectScatter,Line,Page
from pyecharts import options as opts
from pyecharts.faker import Faker
#读取数据
df = pd.read_csv('./总览.csv')
df.columns=['总序列','排名1','书名1','vip月票','排名2','书名2','月票数','排名3','书名3','畅销指数','排名3','书名4','收藏数']
#vip月票数做成一个玫瑰图
def drow_Pie() -> Pie:
    name=df['书名1'].values.tolist()
    num=df['vip月票'].values.tolist()
    data_pair1 = [i for i in zip(name,num)]
    #print(data_pair1)
    A=(
        Pie()
        .add("",data_pair1,
             radius=["25%","75%"],
             rosetype="radius",
            )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="vip月票",pos_left="50%"),
            legend_opts=opts.LegendOpts(
                orient="vertical",
                pos_left="1%",
                pos_top="10%"
            )
        )
        .set_series_opts(
            label_opts=opts.LabelOpts(formatter="{b}:{d}%")
        )
    )
    return A
#将畅销指数，做成词云图
def drow_W() ->WordCloud:
    name1=df['书名3'].values.tolist()
    num1=df['畅销指数'].values.tolist()
    data_pair2 = [i for i in zip(name1,num1)]
    #print(data_pair2)

    B = (
        WordCloud()
        .add(series_name="畅销指数", data_pair=data_pair2, word_size_range=[20, 100],is_draw_out_of_bound=False)
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title="畅销指数", title_textstyle_opts=opts.TextStyleOpts(font_size=15)
            ),
            tooltip_opts=opts.TooltipOpts(is_show=True),
        )
    )
    return B

def drow_B()  ->Bar:
    #将收藏做成柱状图Q
    name2=df['书名4'].values.tolist()
    num2=df['收藏数'].values.tolist()
    c = (
        Bar()
        .add_xaxis(name2)
        .add_yaxis("收藏数", num2, color="blue")
        .set_global_opts(
            title_opts=opts.TitleOpts(title="收藏数前10小数收藏量"),
            datazoom_opts=[opts.DataZoomOpts(), opts.DataZoomOpts(type_="inside")],
        )
    )
    return c
#涟漪图
def drow_E() ->EffectScatter:
    name3 = df['书名2'].values.tolist()
    num3 = df['月票数'].values.tolist()

    D = (
        EffectScatter()
        .add_xaxis(name3)
        .add_yaxis("月票数", num3)
        .set_global_opts(title_opts=opts.TitleOpts(title="散点图_小说月票数    "))
    )
    return D
def drow_L() -> Line:
    #折线图
    name4 = df['vip月票']
    name5 = df['书名2'].values.tolist()
    num4 = df['月票数']
    E = (
        Line()
        .add_xaxis(name5)
        .add_yaxis("vip月票", name4, is_smooth=True)
        .add_yaxis("月票", num4 / 10, is_smooth=True)
        .set_series_opts(
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Line_折线图小说"),
            xaxis_opts=opts.AxisOpts(
                axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                is_scale=False,
                boundary_gap=False,
            ),
        )
    )
    return E
def page_draggable_layout():
    page = Page(layout=Page.SimplePageLayout)
    page.add(
        drow_B(),
        drow_E(),
        drow_L(),
        drow_Pie(),
        drow_W()
    )
    page.render("组合.html")

if __name__ == "__main__":
    page_draggable_layout()